home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #5 & #6 / Amiga Plus CD - 1995 - No. 5 and 6.iso / pd / serien / purity / nr.36 / littleremind / littleremind.p < prev    next >
Text File  |  1994-09-17  |  5KB  |  222 lines

  1.   
  2.  
  3. Program LittleRemind;
  4.  
  5. { * benötigt KickStart 2.0 oder höher ! * }
  6.  
  7. { * Auf dem Rüthener Treffen kurz zusammengehackt, für den ebenso * }
  8. { * gestreßten wie auch verschnupften Andreas Mauß ...  :)        * }
  9. { * Zusammengehackt von "Diesel" Bernd Künnen. Sourcecode und     * }
  10. { * Programm sind Public Domain.        17.09.1994      * }
  11.  
  12.  
  13. { * Zweck des Programmes ist es, innerhalb eines bestimmten Zeit- * }
  14. { * abstandes ein Kommando auszuführen. Grundlage dafür war Andis * }
  15. { * bedürfnis, alle paar Wochen automatisch 'ABackup' gestartet   * }
  16. { * zu bekommen ...  =;-)                      * }
  17.  
  18.  
  19. {$I "Include:dos/dos.i"          }
  20. {$I "Include:exec/libraries.i"   }
  21. {$I "Include:utils/stringlib.i"  }
  22. {$I "Include:utils/parameters.i" }
  23. {$I "Include:utility/Date.i"     }
  24.  
  25.  
  26. Const
  27.     cd_size = SizeOf( ClockData );    { Größe des verw, Records }
  28.  
  29.                       { Datei mit Zeit-Daten }
  30.     s_file  : String = "S:LittleRemind_lasttime";
  31.  
  32.     Monat   : Array[1..12] of Short =  { Anzahl Tage Jan. bis Dez. }
  33.           ( 31,59,90,120,151,181,212,243,273,304,334,365 );
  34.  
  35. var
  36.     dst        : DateStampRec;
  37.     hora_old,
  38.     hora_new    : ClockDataPtr;
  39.     
  40.     sys_seconds,
  41.     differz,
  42.     old_day,
  43.     new_day        : Integer;
  44.  
  45.     hdl        : FileHandle;
  46.     UtilityBase    : Address;
  47.  
  48.     time_out    : Array[1..10] of Char;
  49.     time_int    : Integer;
  50.     x_command    : String;
  51.  
  52.  
  53. { ---------------------------------------------------------------- }
  54.  
  55. { Zum sauberen Verlassen des Programms, egal wo ... }
  56.  
  57. Procedure CleanExit( why: String; rt : Integer);
  58. Begin
  59.     { Bibliothek schließen }
  60.     If UtilityBase <> NIL then CloseLibrary( UtilityBase );
  61.  
  62.     { Datei schließen }
  63.     If hdl <> nil then  DosClose(hdl);
  64.  
  65.     { Ggf. Fehlermeldung }
  66.     If why <> nil then  writeln(why);
  67.     Exit(rt);
  68.  
  69. end;
  70.  
  71. { ---------------------------------------------------------------- }
  72.  
  73. Procedure Init;
  74. Var
  75.     z, zahl, multi : Integer;
  76.  
  77. Begin
  78.     { Kleine Begrüßung }
  79.     Writeln(" LittleRemind V1.0, (P)1994 by Diesel - Public Domain");
  80.  
  81.     { Bibliothek öffnen, für Amiga2Date() }
  82.     UtilityBase := OpenLibrary( "utility.library", 37);
  83.     If UtilityBase = NIL then CleanExit("Benötige Kickstart >= 2.0 !", 20);
  84.  
  85.     { Zu verwendende Datenbereiche initialisieren }
  86.     New( hora_old );
  87.     New( hora_new );
  88.     x_command := AllocString(80);
  89.  
  90.     { Parameter holen }
  91.     GetParam( 1, Adr(time_out) );
  92.     GetParam( 2, x_command );
  93.  
  94.     { Keine Parameter ? }
  95.     If strlen( x_command ) = 0
  96.     then
  97.       CleanExit("Aufruf: LittleRemind Auszeit(in Tagen) Kommando\n   Z.B. LittleRemind 14 \"type s:EsIstZeit.txt\" ", 10);
  98.  
  99.     multi := 1;
  100.  
  101.     { Parameter-Tageszahl nach Integer konvertieren } 
  102.     for z := strlen( Adr(time_out) ) downto 1 do begin    { Rückwärts }
  103.     
  104.       zahl := Byte( time_out[z] ) - Byte('0');    { '1'/Char -> 1/int }
  105.       If (zahl > -1) AND (zahl < 10)  Then        { Nur 0-9 zulassen  }
  106.       begin
  107.         Inc( time_int, (zahl * multi) );
  108.         multi := 10 * multi;
  109.       end;
  110.     end;
  111.  
  112. End;
  113.  
  114. { ---------------------------------------------------------------- }
  115.  
  116. { Aktuelles Datum in Datei schreiben } 
  117.  
  118. Procedure Schreibe_NeueZeit( newtime: ClockDataPtr );;
  119. Begin
  120.     { Datei öffnen } 
  121.     hdl := DosOpen( s_file, mode_newfile );
  122.     If hdl = NIL then
  123.       CleanExit(" FEHLER: Kann Datei S:LittleRemind_lasttime nicht erzeugen !",10);
  124.  
  125.     { Schreiben ... }
  126.     If (DosWrite( hdl, newtime, CD_Size ) <> CD_Size )
  127.     Then CleanExit("FEHLER beim Schreiben in Datei !", 10);
  128.  
  129.     { Datei schließen }
  130.     DosClose( hdl );
  131.     hdl := NIL;
  132.  
  133. End;
  134.  
  135. { ---------------------------------------------------------------- }
  136.  
  137. { Beim Erst-Start erstmal eine Datei anlegen ... }
  138.  
  139. Procedure Erzeuge_Datei;
  140. Begin
  141.     Write("Datei ", s_file, " nicht vorhanden.\nErzeuge...");
  142.     DosClose(hdl);
  143.  
  144.     { Datei anlegen, mit aktiellem Datum }
  145.     Schreibe_NeueZeit( hora_new );
  146.  
  147.     { Uuuund Tschüßßß ! }
  148.     CleanExit("fertig.",0);
  149.  
  150. End;
  151.  
  152. { ---------------------------------------------------------------- }
  153.  
  154. { Hier wird das gewünschte Kommando ausgeführt. Läßt sich nach  }
  155. { eigenen Anspüchen ausbauen.                     }
  156.  
  157. Procedure Do_Action;
  158. Begin
  159.     If Execute( x_command, nil, nil)<> True Then;
  160. end;
  161.  
  162. { ---------------------------------------------------------------- }
  163.  
  164. begin
  165.     { Alles initialisieren }
  166.     Init;
  167.  
  168.     { Systemzeit holen }
  169.     DateStamp( dst );
  170.  
  171.     { Sekunden seit 01.01.1978, 0:00 Uhr }
  172.     sys_seconds :=    (dst.ds_days * 24 * 60 * 60)
  173.             + (dst.ds_minute * 60);
  174.  
  175.     { Umwandeln in 'lesbaren' Record }
  176.     Amiga2Date( sys_seconds, hora_new );
  177.  
  178.     { Schon Datei da ? }
  179.     hdl := DosOpen( s_file, mode_oldfile );
  180.     if hdl = NIL then
  181.       Erzeuge_Datei;    { Nicht ? Dann erzeuge ... }
  182.  
  183.     { Alte Daten laden ... }
  184.     If DosRead( hdl, hora_old, CD_Size) <> CD_Size
  185.     Then CleanExit("FEHLER beim Lesen von S:LittleRemind_lasttime\nBitte löschen Sie die Datei und starten sie LittleRemind neu.", 10);
  186.     DosClose(hdl);
  187.     hdl := NIL;
  188.  
  189.     { Erstmal Systemzeit ausgeben }
  190.     With hora_new^ do begin
  191.       WriteLn( " Sternzeit ", mday, ".", month, ".", year,
  192.                     "  ", hour, ":", min );
  193.     end;
  194.  
  195.     { Differenz seit letztem Aufruf MIT Action berechnen }
  196.     old_day := Monat[hora_old^.month] + hora_old^.mday;
  197.     new_day := Monat[hora_new^.month] + hora_new^.mday;
  198.     differz := new_day - old_day;
  199.  
  200.     { Seit letztem Aufruf MIT Action Jahreswechsel ?? }
  201.     If   differz < 0
  202.     then differz := ( 365 - old_day ) + new_day;
  203.  
  204.     { Wenn Zeitspanne überschritten, ACTION !!! }
  205.     If differz >= time_int
  206.     then begin
  207.  
  208.       { Aktuelles Datum (=Datum der letzen Action) in Datei speichern }
  209.       Write(" Erneuere ", s_file, " ... ");
  210.       Schreibe_NeueZeit( hora_new );
  211.       Writeln("fertig");
  212.  
  213.       { GO for it ! }
  214.       Do_Action;
  215.  
  216.     end;
  217.  
  218.     { Das wars .... }
  219.      Cleanexit(NIL,0);
  220.  
  221. end.
  222.